/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.com.pps.dao;

import java.sql.Types;
import org.springframework.jdbc.core.PreparedStatementCreatorFactory;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import vn.com.pps.entities.PupilEvent;

/**
 *
 * @author Dai
 */
public class PupilEventDAO extends BaseDAO implements IPupilEventDAO{

    @Override
    public int insert(PupilEvent pupilEvent) {
        String sqlInsert="INSERT INTO tblpupilevents(ID,PupilID,Event,CreatedDate) VALUES(?,?,?,?)";
         Object[] params = new Object[]{null,pupilEvent.getPupilID(),pupilEvent.getEvent(),pupilEvent.getCreatedDate()
        };
        PreparedStatementCreatorFactory psc =
                    new PreparedStatementCreatorFactory(sqlInsert);
            psc.addParameter(new SqlParameter("ID", Types.INTEGER));
            psc.addParameter(new SqlParameter("PupilID", Types.INTEGER));
            psc.addParameter(new SqlParameter("Event", Types.VARCHAR));
            psc.addParameter(new SqlParameter("CreatedOn", Types.TIMESTAMP));
            psc.setReturnGeneratedKeys(true);
            KeyHolder generatedKeyHolder = new GeneratedKeyHolder();
            getJdbcTemplate().update(psc.newPreparedStatementCreator(params),
                    generatedKeyHolder);
            return generatedKeyHolder.getKey().intValue();
    }

    @Override
    public int update(PupilEvent pupilEvent) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int delete(int id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Page<PupilEvent> getPupilEvents(int pageNo, int pageSize, String whereClause) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int getCount(String whereClause) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public PupilEvent getPupilEvent(Integer id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
